package com.dragon.repository.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dragon.repository.config.annotation.DataScope;
import com.dragon.repository.entity.WarehouseInout;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 * 出入库 Mapper 接口
 * </p>
 *
 * @author sy
 * @since 2023-11-14
 */
@Mapper
public interface WarehouseInoutMapper extends BaseMapper<WarehouseInout> {

    /**
     * 分页
     * @param inoutPage
     * @param inoutType
     * @param type
     * @param id
     * @return
     */
    @Select("<script> " +
            "SELECT w.* FROM dragon_warehouse_inout w WHERE 1=1 " +
            "<if test='inoutType != null and inoutType != \"\"'> "+
            " and w.inout_type = #{inoutType} " +
            "</if> " +
            "<if test='type != null and type != \"\"'> "+
            " and w.type = #{type}" +
            "</if> " +
            "<if test='id != null and id != \"\"'> "+
            " and w.id = #{id} " +
            "</if> " +
            "ORDER BY w.inout_time" +
            "</script>")
    @DataScope(adminField = "responsible_id", isCheckAdmin = false, authCodeString = "warehouseIn")
    Page<WarehouseInout> selectInoutPage(Page<WarehouseInout> inoutPage, Integer inoutType, Integer type, Integer id);

    /**
     * 获取最大编号
     * @param code
     * @return
     */
    @Select("SELECT MAX(inout_code) FROM dragon_warehouse_inout WHERE inout_code LIKE CONCAT(#{code},'%')")
    String maxRoundInoutNumber(String code);
}
